// --------------------------------------------------------------------------------------------------------------------
// <copyright file="frmError.cs" company="SmartPlan">
//   SmartPlan 2011
// </copyright>
// <summary>
//   Defines the frmError type.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace DbDiff.WinClient.Forms
{
    using System;
    using System.Drawing;
    using System.Windows.Forms;
    using Common.Helper;

    /// <summary>
    /// The frm error.
    /// </summary>
    public class FrmError : frmDialogBase
    {
        /// <summary>
        /// The label 2.
        /// </summary>
        private Label label2;

// private IContainer Components = null;

        /// <summary>
        /// The _message.
        /// </summary>
        private readonly string _message;

        /// <summary>
        /// The txt message.
        /// </summary>
        private TextBox txtMessage;

        /// <summary>
        /// The txt description.
        /// </summary>
        private TextBox txtDescription;

        /// <summary>
        /// The _description.
        /// </summary>
        private readonly string _description;

        #region Constructors

        /// <summary>
        /// Initializes a new instance of the <see cref="FrmError"/> class.
        /// </summary>
        public FrmError()
        {
            // This call is required by the Windows Form Designer.
            this.InitializeComponent();

            // TODO: Add any initialization after the InitializeComponent call
            this._message = string.Empty;
            this._description = string.Empty;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="FrmError"/> class.
        /// </summary>
        /// <param name="message">
        /// The message.
        /// </param>
        /// <param name="description">
        /// The description.
        /// </param>
        public FrmError(string message, string description)
        {
            // This call is required by the Windows Form Designer.
            this.InitializeComponent();

            // TODO: Add any initialization after the InitializeComponent call
            this._message = message;
            this._description = description;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="FrmError"/> class.
        /// </summary>
        /// <param name="e">
        /// The event args
        /// </param>
        public FrmError(Exception e)
        {
            // This call is required by the Windows Form Designer.
            this.InitializeComponent();

            // TODO: Add any initialization after the InitializeComponent call
            this._message = e.Message;
            this._description = string.Empty;

            Exception ex = e;
            while (ex != null)
            {
                this._description += "Message: " + ex.Message + Environment.NewLine;
                if (ex is DbDiffException)
                {
                    this._description += "Caller: " + ((DbDiffException) ex).Caller + Environment.NewLine;
                }

                this._description += "Source: " + ex.Source + Environment.NewLine;
                this._description += "Stacktrace: " + ex.StackTrace + Environment.NewLine;

                ex = ex.InnerException;
            }
        }

        #endregion Constructors

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">
        /// The disposing.
        /// </param>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (this.components != null)
                {
                    this.components.Dispose();
                }
            }

            base.Dispose(disposing);
        }

        #region Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.txtMessage = new TextBox();
            this.label2 = new Label();
            this.txtDescription = new TextBox();
            this.groupMain.SuspendLayout();
            this.SuspendLayout();

// btnOk
            this.btnOk.Location = new Point(312, 320);
            this.btnOk.Name = "btnOk";
            this.btnOk.Click += new EventHandler(this.btnOk_Click);

// btnCancel
            this.btnCancel.Location = new Point(392, 320);
            this.btnCancel.Name = "btnCancel";
            this.btnCancel.Click += new EventHandler(this.btnCancel_Click);

// groupMain
            this.groupMain.Controls.Add(this.txtDescription);
            this.groupMain.Controls.Add(this.txtMessage);
            this.groupMain.Controls.Add(this.label2);
            this.groupMain.Name = "groupMain";
            this.groupMain.Size = new Size(472, 312);

// txtMessage
            this.txtMessage.Anchor =
                (System.Windows.Forms.AnchorStyles)
                (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                  | System.Windows.Forms.AnchorStyles.Right));
            this.txtMessage.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
            this.txtMessage.Location = new Point(8, 16);
            this.txtMessage.Multiline = true;
            this.txtMessage.Name = "txtMessage";
            this.txtMessage.ReadOnly = true;
            this.txtMessage.Size = new Size(456, 40);
            this.txtMessage.TabIndex = 1;
            this.txtMessage.Text = string.Empty;

// label2
            this.label2.Location = new Point(8, 72);
            this.label2.Name = "label2";
            this.label2.Size = new Size(112, 24);
            this.label2.TabIndex = 2;
            this.label2.Text = "Description / history";

// txtDescription
            this.txtDescription.Anchor =
                (System.Windows.Forms.AnchorStyles)
                ((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                   | System.Windows.Forms.AnchorStyles.Left)
                  | System.Windows.Forms.AnchorStyles.Right));
            this.txtDescription.Location = new Point(8, 96);
            this.txtDescription.Multiline = true;
            this.txtDescription.Name = "txtDescription";
            this.txtDescription.ReadOnly = true;
            this.txtDescription.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
            this.txtDescription.Size = new Size(456, 206);
            this.txtDescription.TabIndex = 3;
            this.txtDescription.Text = string.Empty;

// frmError
            this.AutoScaleBaseSize = new Size(5, 13);
            this.ClientSize = new Size(472, 349);
            this.Cursor = System.Windows.Forms.Cursors.Default;
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Sizable;
            this.Name = "frmError";
            this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
            this.Text = "Error";
            this.Load += new EventHandler(this.frmError_Load);
            this.groupMain.ResumeLayout(false);
            this.ResumeLayout(false);
        }

        #endregion

        /// <summary>
        /// The update form data.
        /// </summary>
        protected override void UpdateFormData()
        {
            this.txtMessage.Text = this._message;
            this.txtDescription.Text = this._description;
        }

        /// <summary>
        /// The frm error_ load.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The event args
        /// </param>
        private void frmError_Load(object sender, EventArgs e)
        {
            this.btnOk.Visible = false;
            this.btnCancel.Text = "&Close";
        }

        /// <summary>
        /// The btn ok_ click.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The event args
        /// </param>
        private void btnOk_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        /// <summary>
        /// The btn cancel_ click.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The event args
        /// </param>
        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}

